﻿namespace Morus.Infrastructure
{
    using System;
    using System.Linq.Expressions;

    public sealed class NotSpecification<T> : Specification<T>
        where T : class
    {
        private readonly ISpecification<T> _originalCriteria;

        public NotSpecification(ISpecification<T> original)
        {
            Check.Argument.IsNotNull(original, "original");

            _originalCriteria = original;
        }

        public override Expression<Func<T, bool>> Expression
        {
            get
            {
                var body = System.Linq.Expressions.Expression.Not(_originalCriteria.Expression.Body);
                return System.Linq.Expressions.Expression.Lambda<Func<T, bool>>(body, _originalCriteria.Expression.Parameters);
            }
        }
    }
}
